var COS=require('cos-nodejs-sdk-v5')
var cos=new COS()
// var crypto=require('crypto')
//获取腾讯云存储桶下载Authorization
let secretId='AKIDTltoTr0sTord8NL2ScXBYeU4TdxLabPx'
let secretKey='NEuMl28IFxAA0dz4tSr55qNfh6MPEo9F'
// var cos = new COS({
//   SecretId:secretId,
//   SecretKey: secretKey
// })
function getAuthorization(params){
  return COS.getAuthorization({
    SecretId:secretId,
    SecretKey:secretKey,
    Bucket:'mirror-1305990023',
    Region:'ap-chongqing',
    Method:'put',
    Key:params.name,
    Expires:60*60,
  })
}
module.exports.getAuthorization=getAuthorization
// function getUploadAuthorization(){
//   return COS.getObjectUrl({
//     SecretId:secretId,
//     SecretKey:secretKey,
    // Bucket:'mirror-1305990023',
    // Region:'ap-chongqing',
//     Method:'PUT',
//     Key:'/pic/',
//     Sign:false
//   })
// }
// // 手动生成签名
// function getAuthorization(){
//   //sh1HttpString == HttpString(请求头中的)
//   //1、生成KeyTime
//   let date=new Date()
//   KeyTime = date.getTime()
//   KeyTime=KeyTime+';'+(KeyTime+60*60*24)
//   //2、生成SingKey
//   let signKey=crypto.createHmac('sha1','NEuMl28IFxAA0dz4tSr55qNfh6MPEo9F').update(KeyTime).digest('hex')
//   //3、生成 UrlParamList 和 HttpParameters（可以为空）
//   //4、生成 HeaderList 和 HttpHeaders
//   //遍历请求头部
//   let headers={
//     host:'https://mirror-1305990023.cos.ap-chongqing.myqcloud.com',
//     date:date
//   }
//   let headerMapper=new Map()
//   let HeaderList=[]
//   let HttpHeaders=[]
//   console.log(headers)
//   for( item in headers){
//     headerMapper.set(item,headers[item])
//   }
//   headerMapper.forEach((value,key,headerMapper)=>{
//     HeaderList.push(encodeURI(key))
//     HttpHeaders.push(encodeURI(key)+'='+encodeURI(value))
//   })
//   HeaderList=HeaderList.join(';')
//   HttpHeaders=HttpHeaders.join('&')
//   console.log(HttpHeaders)
//   let sha1HttpString=crypto.createHash('sha1').update('ExampleHttpString').digest('hex')
  
//   console.log(sha1HttpString,signKey)
//   data.HttpString=sha1HttpString
//   data.signKey=signKey
// }
// module.exports.getUploadAuthorization=getUploadAuthorization()